package DaoImpl;



import java.util.List;

import Dao.CriteriaProcurement;
import Dao.DAO;
import Dao.ProcurementDao;
import DoMain.Procurement;

public class ProcurementDaoJdbcImpl extends DAO<Procurement> implements ProcurementDao{

	@Override
	public List<Procurement> getAll() {
		
		String sql="select proNo,proMan,proMaterial,proDate,proPay,status from procurement";
		
		return getForList(sql);
	}

	@Override
	public void save(Procurement procurement) {
		
		String sql="insert into procurement(proMan,proMaterial,proPay)values(?,?,?)";
		
		update(sql,procurement.getProMan(),procurement.getProMaterial(),procurement.getProPay());
		
	}

	@Override
	public void delete(Integer proNo) {
		
		String sql="delete from procurement where proNo=?";
		
		update(sql,proNo);
	}

	@Override
	public void update(Procurement procurement) {
		
		String sql="update procurement set proMan=?,proMaterial=?,proPay=?,status=? where proNo=?";
		
		update(sql,procurement.getProMan(),procurement.getProMaterial(),procurement.getProPay(),procurement.getStatus(),procurement.getProNo());
		
	}

	@Override
	public Procurement get(Integer proNo) {

		String sql="select proNo,proMan,proMaterial,proDate,proPay,status from procurement where proNo=?";
		
		return get(sql,proNo);
	}

	@Override
	public long getCountWithName(String proMan) {

		String sql="select count(proNo) from procurement where proMan=?";
		
		return getForValue(sql,proMan);
	}

	@Override
	public List<Procurement> getForListWithCriteriaProcurement(CriteriaProcurement cp) {
		
		String sql="select proNo,proMan,proMaterial,proDate,proPay,status from procurement where proMan like ? and proMaterial like ? and proDate like ? and proPay like ? and status like ?";
		
		return getForList(sql,cp.getProMan(),cp.getProMaterial(),cp.getProDate(),cp.getProPay(),cp.getStatus());
	}

	@Override
	public int getCount(){
	
		String sql="select count(*) from procurement";
		
		return getForValue(sql);
	}

	@Override
	public List<Procurement> getPage(int begin, int end) {
		
		String sql="select * from procurement limit ?,?";
		
		return getForList(sql,begin,end);
	}

	 }

